<extend name="template/base"/>
<block name="area_header">

</block>

<block name="area_body">
    <div class="col-lg-10 col-md-10 col-lg-offset-1 col-md-offset-1 clearfix">
        <h2>Token获取测试</h2>
        <form class="form-horizontal authForm" action="{:U('Api/Token/index')}" method="post">

            <div class="form-group">
                <label class="control-label col-lg-2 col-md-2">授权类型</label>

                <div class="col-lg-10 col-md-10">
                    <select name="grant_type" class="form-control">
                        <option value="password">password</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-lg-2 col-md-2">ClientID(2种模式下有效)</label>
                <div class="col-lg-10 col-md-10">
                    <input type="text" name="client_id" class="form-control" value="by559a8de1c325c1"/>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-lg-2 col-md-2">appsecret(client_credentials 模式下有效)</label>
                <div class="col-lg-10 col-md-10">
                    <input type="text" name="client_secret" class="form-control"  value="aedd16f80c192661016eebe3ac35a6e7"/>
                </div>
            </div>

            <div class="form-group">
                <label class="control-label col-lg-2 col-md-2">用户登录账号</label>
                <div class="col-lg-10 col-md-10">
                    <input type="text" name="username" class="form-control"  value="itboye"/>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-lg-2 col-md-2">用户密码</label>
                <div class="col-lg-10 col-md-10">
                    <input type="text" name="password" class="form-control"  value="1"/>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-lg-2 col-md-2">scope</label>
                <div class="col-lg-10 col-md-10">
                    <input type="text" name="scope" class="form-control"  value="base"/>
                </div>
                <div class="help-block">默认为null时，表示所有，指定支持值</div>
            </div>
            <div class="form-group">
                <label class="control-label col-lg-2 col-md-2">&nbsp;</label>

                <div class="col-lg-10 col-md-10">
                    <button type="button" class="btn btn-sm btn-primary js_submit"  >提交</button>
                </div>
            </div>
        </form>

        <div class="well js_panel">
            <pre>
                <code>

                </code>
            </pre>
        </div>
    </div>
</block>

<block name="area_footer">
    <script type="text/javascript">
        $(function(){
            $(".js_submit").click(function(ev){
                var that = ev.target;
                $(that).button("loading");
                var form = $(".authForm");
                var query = form.serialize();
                var target = "{:U('Api/Token/index')}";
                $.post(target, query).always(function() {
                    setTimeout(function(){
                        $(that).button("reset");
                    },1400);
                }).done(function(data) {
                    console.log(data);
                    $(".js_panel code").text(JSON.stringify(data.info));
                }).fail(function(data){
                    var json = JSON.parseJSON(data.responseText);
                    console.log(json);

                });//end post

            })
        });
    </script>
</block>
